<?php
/**
 * Created by PhpStorm.
 * UsersF: Mloong
 * Date: 2019/1/10
 * Time: 11:22
 */

namespace app\admin\service;


use app\admin\model\Banner;
use app\lib\exception\MysqlErrorException;
use think\Db;

class BannerService
{
    private $model;
    public function __construct()
    {
        $this->model = new Banner();
    }

    public function addOrUpBanner($post_data)
    {
        array_key_exists('status',$post_data) ? $post_data['status'] == 1 : $post_data['status'] == 0;
        if(array_key_exists('banner_id', $post_data) == true){
            $post_data['up_time'] = now_time();
            $result = $this->model->where('banner_id','=',$post_data['banner_id'])
                ->update($post_data);
            if($result){
                return [
                   'success' => true,
                   'msg' => '更新成功'
                ];
            }else{
                return [
                    'success' => false,
                    'msg' => '更新失败'
                ];
            }
        }else{
            $post_data['add_time'] = now_time();
            $result = $this->model->create($post_data);
            if($result){
                return [
                    'success' => true,
                    'msg' => '更新成功'
                ];
            }else{
                return [
                    'success' => false,
                    'msg' => '更新失败'
                ];
            }
        }
    }
}